package me.zhengjie.modules.quartz.task.processing;

import com.qiaofang.applet.common.util.RedisKeyUtil;
import lombok.extern.slf4j.Slf4j;
import me.zhengjie.modules.sync.processing.FirsthandEstateSyncProcessing;
import me.zhengjie.utils.RedisUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.concurrent.TimeUnit;

/*
* 新房解析TASK
* */
@Slf4j
@Component
public class FirsthandEstateProcessingTask {

    @Autowired
    FirsthandEstateSyncProcessing firsthandEstateSyncProcessing;

    @Autowired
    private RedisUtils redisUtils;

    public void processing(){
        String taskKey = RedisKeyUtil.getTaskKey(this.getClass().getSimpleName());
        if (redisUtils.hasKey(taskKey)){
            return;
        }
        redisUtils.set(taskKey, "", 1, TimeUnit.HOURS);
        try {
            log.info("firsthandEstateSyncProcessing run start");
            Long startTime = System.currentTimeMillis();
            firsthandEstateSyncProcessing.run();
            Long endTime = System.currentTimeMillis();
            log.info("firsthandEstateSyncProcessing run end {}", (endTime - startTime));
        } catch (Exception e) {
            log.error("firsthandEstateSyncProcessing error", e);
        }
        redisUtils.del(taskKey);
    }

}
